<template>
  <div>
    <div class="title">
      <el-row>
        <el-col :span="1" style="width: 50px;">
          <span style="color:#757575;">位置 :</span>
        </el-col>
        <el-col :span="20">
          <span @click="tableshow" class="hand" :class="{'textactive' : !secondshow}">简历推送</span>
          <span v-if="secondshow" :class="{'textactive' : secondshow}">> {{secondtitle}}</span>
        </el-col>
      </el-row>
    </div>
    <div class="posttable" v-show="!addShow">
      <el-row type="flex" justify="center">
        <el-col :span="23">
          <div>
            <div
              class="tabletitle"
              style="float: left;margin-left: -10px;margin-top: 20px;margin-bottom: 20px;"
            >
              <h4>上传数量</h4>
            </div>
            <el-table class="resutable" :data="tableData1" ref="table1">
              <el-table-column label="推送客户" width="120">
                <template slot-scope="scope">
                  <!-- prop="name" -->
                  <span style="color:#1198ff;">{{scope.row.customer}}</span>
                </template>
              </el-table-column>

              <el-table-column prop="totalcount" label="需要完成数量"></el-table-column>
              <el-table-column prop="existcount" label="已完成数量"></el-table-column>
              <el-table-column prop="surpluscount" label="未完成数量"></el-table-column>
              <el-table-column prop="state" label="结果"></el-table-column>
            </el-table>
            <div class="pager">
              <el-pagination
                @size-change="handleSizeChange1"
                @current-change="pagehandleCurrentChange1"
                :current-page="currentPage1"
                :page-sizes="[5,10,15]"
                :page-size="pagesize1"
                layout="total, sizes, prev, pager, next, jumper"
                :total="totalcount1"
              ></el-pagination>
            </div>
          </div>

          <el-row type="flex" justify="center">
            <el-col>
              <div class="tabletitle" style="float: left;margin-left: -10px;line-height: 43px;">
                <h4>上传情况</h4>
              </div>
              <div style="float: right;">
                <el-row type="flex" justify="space-between" style="margin-top: 11px;" class="btn">
                  <el-input
                    size="small"
                    placeholder="查找"
                    style="width: 136px;"
                    v-model.trim="inputValue"
                    @keydown.enter.native="searchMsg"
                  >
                    <i
                      slot="suffix"
                      class="el-input__icon el-icon-search"
                      style="cursor: pointer;"
                      @click="searchMsg"
                    ></i>
                  </el-input>
                  <div style="margin-left:5px">
                    <el-button
                      class="push"
                      @mousedown.native="pushDown"
                      @mouseup.native="pushUp"
                      :class="{'active' : newcolor}"
                      size="small"
                      v-if="jiaofu"
                      round
                      @click="pushClick"
                    >推送</el-button>
                    <el-button
                      class="back"
                      @mousedown.native="backDown"
                      @mouseup.native="backUp"
                      :class="{'active1' : newcolor1}"
                      v-if="jiaofu"
                      size="small"
                      round
                      @click="backClick"
                    >退回</el-button>
                  </div>
                </el-row>
              </div>
            </el-col>
          </el-row>

          <el-table
            style="margin-top: 20px;"
            class="resutable"
            :data="tableData"
            highlight-current-row
            :row-key="getRowKey"
            ref="multipleTable"
            @selection-change="handleSelectionChange"
          >
            <el-table-column
              style="border:1px solid #333"
              type="selection"
              :reserve-selection="true"
              width="55"
            ></el-table-column>
            <el-table-column label="推送客户" width="120">
              <template slot-scope="scope">
                <!-- prop="name" -->
                <span
                  style="cursor: pointer; color:#1198ff;"
                  @click="viewdetail(scope.row)"
                >{{scope.row.customerName}}</span>
              </template>
            </el-table-column>
            <el-table-column label="需求编号" width="140">
              <template slot-scope="scope">
                <!-- prop="name" -->
                <span
                  style="cursor: pointer; color:#1198ff;"
                  @click="viewjobdemand(scope.row)"
                >{{scope.row.requireNum}}</span>
              </template>
            </el-table-column>
            <el-table-column prop="postName" label="推送职位"></el-table-column>
            <el-table-column prop="postLevel" label="职位级别"></el-table-column>
            <el-table-column prop="area" label="所属区域"></el-table-column>
            <el-table-column label="姓名">
              <template slot-scope="scope">
                <!-- prop="name" -->
                <span>
                  <a
                    :href="scope.row.group+'/'+scope.row.fileAddress"
                    class="resumeLink"
                    target="_blank"
                  >{{scope.row.name}}</a>
                </span>
              </template>
            </el-table-column>
            <el-table-column label="毕业时间">
              <template slot-scope="scope">
                <span>{{scope.row.graduationTime | converTime("YYYY-MM")}}</span>
              </template>
            </el-table-column>
            <el-table-column label="出生年月">
              <template slot-scope="scope">
                <span>{{scope.row.birthday | converTime("YYYY-MM")}}</span>
              </template>
            </el-table-column>
            <el-table-column prop="phone" label="联系方式"></el-table-column>
            <el-table-column prop="status" label="离职状态"></el-table-column>
            <el-table-column prop label="期望薪资">
              <template slot-scope="scope">
                <span>{{scope.row.expectSalary}}k*{{scope.row.expectSalaryNum}}</span>
              </template>
            </el-table-column>
            <el-table-column label="到岗时间">
              <template slot-scope="scope">
                <span>{{scope.row.entryTime}}</span>
              </template>
            </el-table-column>
            <el-table-column prop="pusher" label="推送人"></el-table-column>
            <el-table-column label="推送时间">
              <template slot-scope="scope">
                <span>{{scope.row.createTime | converTime("YYYY-MM-DD HH:mm")}}</span>
              </template>
            </el-table-column>
            <el-table-column prop="initialEvaluation" label="初步评价" show-overflow-tooltip></el-table-column>
          </el-table>
          <div class="pager">
            <el-pagination
              @size-change="handleSizeChange"
              @current-change="pagehandleCurrentChange"
              :current-page="currentPage"
              :page-sizes="[5,10,15]"
              :page-size="pagesize"
              layout="total, sizes, prev, pager, next, jumper"
              :total="totalcount"
            ></el-pagination>
            <el-dialog
              title="错误"
              :visible.sync="editdialogVisible"
              width="30%"
              :before-close="handleClose"
              class="deletedialog"
            >
              <div style="text-align: center">
                <i class="el-icon-warning" style="font-size: 20px;color: #fcb543;">
                  <span style="font-size: 16px;color: #333;margin-left: 12px;">尚未选择任何简历</span>
                </i>
              </div>
              <span slot="footer" class="dialog-footer">
                <el-button class="sure" round @click="handleOpen">确 定</el-button>
                <el-button round @click="handleClose" class="cancel">取 消</el-button>
              </span>
            </el-dialog>
            <el-dialog
              title="错误"
              :visible.sync="dialogVisible"
              width="30%"
              :before-close="close"
              class="deletedialog"
            >
              <div style="text-align: center">
                <i class="el-icon-warning" style="font-size: 20px;color: #fcb543;">
                  <span style="font-size: 16px;color: #333;margin-left: 12px;">请每次退回一份简历</span>
                </i>
              </div>
              <span slot="footer" class="dialog-footer">
                <el-button class="sure" round @click="open">确 定</el-button>
                <el-button round @click="close" class="cancel">取 消</el-button>
              </span>
            </el-dialog>
            <el-dialog
              title="错误"
              :visible.sync="requireNumDialogVisible"
              width="30%"
              :before-close="reclose"
              class="deletedialog"
            >
              <div style="text-align: center">
                <i class="el-icon-warning" style="font-size: 20px;color: #fcb543;">
                  <span style="font-size: 16px;color: #333;margin-left: 12px;">需求编号不同</span>
                </i>
              </div>
              <span slot="footer" class="dialog-footer">
                <el-button class="sure" round @click="reclose">确 定</el-button>
                <el-button round @click="reclose" class="cancel">取 消</el-button>
              </span>
            </el-dialog>

            <el-dialog :visible.sync="dialogFormVisible" class="back1" :before-close="cancelSend">
              <el-row>
                <el-col :span="2" style="line-height:28px;color:#0e6195">收件人：</el-col>
                <el-col :span="10" class="receive">
                  <el-select
                    size="mini"
                    v-model="form.receiver"
                    placeholder="请选择收件人邮箱"
                    @change="getcpMail"
                  >
                    <el-option
                      v-for="item in receiveMails"
                      :key="item.id"
                      :label="item.receiveMail"
                      :value="item.receiveMail"
                    ></el-option>
                  </el-select>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="23">
                  <div class="line"></div>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="2" style="line-height:28px;color:#0e6195">
                  <i :class="iconClass" @click="secretAppear"></i>抄送人：
                </el-col>
                <el-col :span="18" style="line-height:28px;font-size:12px;">{{form.cpSendMail}}</el-col>
              </el-row>
              <el-row>
                <el-col :span="23">
                  <div class="darkline"></div>
                </el-col>
              </el-row>
              <el-row v-if="isSecret">
                <el-col :span="2" style="line-height:28px;color:#0e6195">密送：</el-col>
                <el-col :span="6" style="line-height:28px;font-size:12px;">
                  <el-input
                    @blur="secretBlur"
                    v-model="form.secret"
                    placeholder="请输入密送人邮箱"
                    size="mini"
                  ></el-input>
                </el-col>
                <el-col :span="6" :offset="1">
                  <el-alert v-if="emailError" title="请输入正确的邮箱格式" type="error" show-icon></el-alert>
                </el-col>
                <el-col :span="23">
                  <div class="darkline"></div>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="2" style="line-height:28px;color:#999798">主&nbsp;&nbsp;&nbsp;&nbsp;题：</el-col>
                <el-col
                  :span="10"
                  style="line-height:28px;font-size:12px;font-weight:700;"
                >{{this.theme}}</el-col>
              </el-row>
              <el-row>
                <el-col :span="23">
                  <div class="lightLine"></div>
                </el-col>
              </el-row>
              <el-row>
                <el-col v-if="this.file" :span="24">
                  <span
                    v-for="(item,index) in file"
                    :key="index"
                    style="margin-right:10px;line-height:40px"
                  >
                    <a
                      :href="item.fileUrl"
                      class="resumeLink"
                      target="_blank"
                    >{{item.originalFilename}}</a>
                  </span>
                </el-col>
              </el-row>
              <el-row v-if="this.maildata.length > 0">
                <el-row type="flex" justify="center">
                  <el-col :span="23" style="margin-top: 12px;margin-bottom: 28px;">
                    <p>您好:&nbsp;</p>
                    <p>&nbsp; 附件中有{{this.maildata.length}}份符合{{msg}}的简历,请查收！</p>
                    <p>&nbsp; 如有其它问题，请随时与我们联系，感谢大力支持！</p>
                  </el-col>
                </el-row>
                <el-col style="padding-left: 10px;padding-right: 10px;" class="resumepushtable">
                  <el-table class="tablelist" ref="mailtable" :data="maildata" border>
                    <template v-for="(item,index) in header">
                      <el-table-column :label="item.title" :key="index" :width="item.size">
                        <template slot-scope="props">
                          <el-input type="textarea" autosize v-model="props.row[item.prop]" v-if="!item.isWrite"></el-input>
                          <span v-else>{{props.row[item.prop]}}</span>
                        </template>
                      </el-table-column>
                    </template>
                  </el-table>

                  <!-- <el-table
                    class="tablelist"
                    ref="mailtable"
                    :data="maildata"
                    border
                    v-show="maildata[0].customerName != '港交所' && maildata[0].customerName != '旭辉集团' && maildata[0].customerName != '浦发信用卡'"
                  >
                    <el-table-column
                      label="姓名"
                    >
                      <template slot-scope="props">
                        <el-input type="textarea" autosize v-model="props.row.name"></el-input>
                      </template>
                    </el-table-column>
                    <el-table-column
                      label="性别"
                    >
                      <template slot-scope="props">
                        <el-input type="textarea" autosize v-model="props.row.sex"></el-input>
                      </template>
                    </el-table-column>
                    <el-table-column
                      label="岗位"
                    >
                      <template slot-scope="props">
                        <el-input type="textarea" autosize v-model="props.row.postName"></el-input>
                      </template>
                    </el-table-column>
                    <el-table-column
                      label="入职城市"
                    >
                      <template slot-scope="props">
                        <el-input type="textarea" autosize v-model="props.row.area"></el-input>
                      </template>
                    </el-table-column>
                    <el-table-column
                      label="学历"
                    >
                      <template slot-scope="props">
                        <el-input type="textarea" autosize v-model="props.row.education"></el-input>
                      </template>
                    </el-table-column>
                    <el-table-column
                      label="专业"
                    >
                      <template slot-scope="props">
                        <el-input type="textarea" autosize v-model="props.row.speciality"></el-input>
                      </template>
                    </el-table-column>
                    <el-table-column
                      label="毕业院校"
                    >
                      <template slot-scope="props">
                        <el-input type="textarea" autosize v-model="props.row.college"></el-input>
                      </template>
                    </el-table-column>
                    <el-table-column
                      label="毕业时间"
                    >
                      <template slot-scope="props">
                        <el-input type="textarea" autosize v-model="props.row.graduationTime"></el-input>
                      </template>
                    </el-table-column>
                    <el-table-column
                      label="出生年月"
                    >
                      <template slot-scope="props">
                        <el-input type="textarea" autosize v-model="props.row.birthday"></el-input>
                      </template>
                    </el-table-column>
                    <el-table-column
                      label="工作年限"
                      v-if="maildata[0].customerName == '工银瑞信'"
                    >
                      <template slot-scope="props">
                        <el-input type="textarea" autosize v-model="props.row.workSeniority"></el-input>
                      </template>
                    </el-table-column>
                    <el-table-column
                      label="联系电话"
                      v-if="maildata[0].customerName != '中原消费' && maildata[0].customerName != '中原证券'"
                    >
                      <template slot-scope="props">
                        <el-input type="textarea" autosize v-model="props.row.phone"></el-input>
                      </template>
                    </el-table-column>
                    <el-table-column
                      label="候选人邮箱"
                    >
                      <template slot-scope="props">
                        <el-input type="textarea" autosize v-model="props.row.mail"></el-input>
                      </template>
                    </el-table-column>
                    <el-table-column
                      label="是否接受外包"
                      v-if="maildata[0].customerName == '阿里巴巴'"
                    >
                      <template>
                        <span>接受</span>
                      </template>
                    </el-table-column>
                    <el-table-column
                      label="态度是否良好"
                      v-if="maildata[0].customerName == '阿里巴巴'"
                    >
                      <template>
                        <span>良好</span>
                      </template>
                    </el-table-column>
                    <el-table-column
                      label="工作状态"
                    >
                      <template slot-scope="props">
                        <el-input type="textarea" autosize v-model="props.row.status"></el-input>
                      </template>
                    </el-table-column>
                    <el-table-column
                      label="到岗时间"
                    >
                      <template slot-scope="props">
                        <el-input type="textarea" autosize v-model="props.row.entryTime"></el-input>
                      </template>
                    </el-table-column>
                    <el-table-column
                      label="期望薪资"
                      v-if="maildata[0].customerName != '阳光资产' && maildata[0].customerName != '灵雀云' && maildata[0].customerName != '禹洲集团' && maildata[0].customerName != '亿联银行' && maildata[0].customerName != '中关村银行' && maildata[0].customerName != '武汉众邦' && maildata[0].customerName != '浦发信用卡' && maildata[0].customerName != '万国数据' && maildata[0].customerName != '中保车'"
                    >
                      <template slot-scope="props">
                        <el-input type="textarea" autosize v-model="props.row.expectSalary"></el-input>
                      </template>
                    </el-table-column>
                    <el-table-column
                      label="薪数"
                      v-if="maildata[0].customerName != '阳光资产' && maildata[0].customerName != '灵雀云' && maildata[0].customerName != '禹洲集团' && maildata[0].customerName != '亿联银行' && maildata[0].customerName != '中关村银行' && maildata[0].customerName != '武汉众邦' && maildata[0].customerName != '浦发信用卡' && maildata[0].customerName != '万国数据' && maildata[0].customerName != '中保车'"
                    >
                      <template slot-scope="props">
                        <el-input type="textarea" autosize v-model="props.row.expectSalaryNum"></el-input>
                      </template>
                    </el-table-column>
                    <el-table-column
                      label="项目经理"
                      v-if="maildata[0].customerName == '泰康资产' || maildata[0].customerName == '工银瑞信'"
                    >
                      <template slot-scope="props">
                        <el-input type="textarea" autosize v-model="props.row.introducer"></el-input>
                      </template>
                    </el-table-column>
                    <el-table-column
                      label="方便面试时间"
                    >
                      <template slot-scope="props">
                        <el-input type="textarea" autosize v-model="props.row.interviewTime"></el-input>
                      </template>
                    </el-table-column>
                    <el-table-column
                      label="初步评价"
                    >
                      <template slot-scope="props">
                        <el-input type="textarea" autosize v-model="props.row.initialEvaluation"></el-input>
                      </template>
                    </el-table-column>
                    <el-table-column
                      label="推荐简历的公司"
                      v-if="maildata[0].customerName != '旭辉集团'"
                    >
                      <template>
                        <span>神州新桥</span>
                      </template>
                    </el-table-column>
                  </el-table>
                  <el-table
                    ref="mailtableG"
                    :data="mailform"
                    border
                    v-show="maildata[0].customerName == '港交所'"
                    class="gangTable"
                  >
                    <el-table-column label="JR Number">
                      <template slot-scope="props">
                        <el-input type="textarea" autosize v-model="props.row.JRNumber"></el-input>
                      </template>
                    </el-table-column>
                    <el-table-column label="Role">
                      <template slot-scope="props">
                        <el-input type="textarea" autosize v-model="props.row.Role"></el-input>
                      </template>
                    </el-table-column>
                    <el-table-column label="Name">
                      <template slot-scope="props">
                        <el-input type="textarea" autosize v-model="props.row.Name"></el-input>
                      </template>
                    </el-table-column>
                    <el-table-column label="Notice Period">
                      <template slot-scope="props">
                        <el-input type="textarea" autosize v-model="props.row.NoticePeriod"></el-input>
                      </template>
                    </el-table-column>
                    <el-table-column label="Gender">
                      <template slot-scope="props">
                        <el-input type="textarea" autosize v-model="props.row.Gender"></el-input>
                      </template>
                    </el-table-column>
                    <el-table-column label="Year of Birth">
                      <template slot-scope="props">
                        <el-input type="textarea" autosize v-model="props.row.YearofBirth"></el-input>
                      </template>
                    </el-table-column>
                    <el-table-column label="Experience">
                      <template slot-scope="props">
                        <el-input type="textarea" autosize v-model="props.row.Experience"></el-input>
                      </template>
                    </el-table-column>
                    <el-table-column label="Note(ifany)">
                      <template slot-scope="props">
                        <el-input type="textarea" autosize v-model="props.row.Note"></el-input>
                      </template>
                    </el-table-column>
                    <el-table-column label="Language">
                      <template slot-scope="props">
                        <el-input type="textarea" autosize v-model="props.row.Language"></el-input>
                      </template>
                    </el-table-column>
                    <el-table-column label="Rate code">
                      <template slot-scope="props">
                        <el-input type="textarea" autosize v-model="props.row.RateCode"></el-input>
                      </template>
                    </el-table-column>
                    <el-table-column label="Telephone">
                      <template slot-scope="props">
                        <el-input type="textarea" autosize v-model="props.row.Telephone"></el-input>
                      </template>
                    </el-table-column>
                    <el-table-column label="Personal Data Usage Declaration*">
                      <template slot-scope="props">
                        <el-input type="textarea" autosize v-model="props.row.PersonalDataUsageDeclaration"></el-input>
                      </template>
                    </el-table-column>
                  </el-table>
                  <el-table
                    ref="mailtableX"
                    :data="maildata"
                    border
                    v-show="maildata[0].customerName == '旭辉集团'"
                    class="tablelist"
                  >
                    <el-table-column
                      label="序号"
                      type="index"
                      width="50">
                    </el-table-column>
                    <el-table-column
                      label="姓名"
                    >
                      <template slot-scope="props">
                        <el-input type="textarea" autosize v-model="props.row.name"></el-input>
                      </template>
                    </el-table-column>
                    <el-table-column
                      label="性别"
                    >
                      <template slot-scope="props">
                        <el-input type="textarea" autosize v-model="props.row.sex"></el-input>
                      </template>
                    </el-table-column>
                    <el-table-column
                      label="岗位"
                    >
                      <template slot-scope="props">
                        <el-input type="textarea" autosize v-model="props.row.postName"></el-input>
                      </template>
                    </el-table-column>
                    <el-table-column
                      label="联系电话"
                    >
                      <template slot-scope="props">
                        <el-input type="textarea" autosize v-model="props.row.phone"></el-input>
                      </template>
                    </el-table-column>
                  </el-table>
                  <el-table
                    ref="mailtableP"
                    :data="maildata"
                    border
                    v-show="maildata[0].customerName == '浦发信用卡'"
                    class="tablelist"
                  >
                    <el-table-column
                      label="推送时间"
                    >
                      <template slot-scope="props">
                        <el-input type="text" v-model="props.row.pushTime"></el-input>
                      </template>
                    </el-table-column>
                    <el-table-column
                      label="供应商"
                    >
                      <template slot-scope="props">
                        <span v-show="maildata[0].requireNum == 'PFXY20200312-002' || maildata[0].requireNum == 'PFXY20200312-003' || maildata[0].requireNum == 'PFXY20200312-004' || maildata[0].requireNum == 'PFXY20200313-001'">神州新桥</span>
                        <span v-show="maildata[0].requireNum != 'PFXY20200312-002' && maildata[0].requireNum != 'PFXY20200312-003' && maildata[0].requireNum != 'PFXY20200312-004' && maildata[0].requireNum != 'PFXY20200313-001'">上海新炬</span>
                      </template>
                    </el-table-column>
                    <el-table-column
                      label="姓名"
                    >
                      <template slot-scope="props">
                        <el-input type="textarea" autosize v-model="props.row.name"></el-input>
                      </template>
                    </el-table-column>
                    
                    <el-table-column
                      label="岗位"
                    >
                      <template slot-scope="props">
                        <el-input type="textarea" autosize v-model="props.row.postName"></el-input>
                      </template>
                    </el-table-column>
                  
                  </el-table>-->
                </el-col>

                <el-col
                  style="text-indent: 1.5em;margin-top: 30px;margin-left: 10px;margin-bottom: 30px;"
                >
                  <p>周颖</p>
                  <p>软件研发中心 人力资源部</p>
                  <p>
                    <span>公司 :</span>
                    <span>北京神州新桥科技有限公司</span>
                  </p>
                  <p>
                    <span>地址 :</span>
                    <span>北京市海淀区长春桥路11号万柳亿城大厦2号楼16层</span>
                  </p>
                  <p>
                    <span>邮箱 :</span>
                    <span>sinorjyfzx@sino-bridge.com</span>
                  </p>
                  <p>
                    <span>电话 :</span>
                    <span>(+86)15962999175</span>
                  </p>
                </el-col>
              </el-row>
              <div slot="title" class="dialog-title">
                <el-button
                  v-if="!emailError"
                  type="primary"
                  :disabled="!sendEmailKey"
                  @click="sendClick"
                  style="font-size:16px;"
                >
                  <i class="iconfont icon-plane"></i>
                  <span style="margin-left:6px;">发送</span>
                </el-button>
                <el-button @click="cancelSend">取 消</el-button>
              </div>
            </el-dialog>
            <el-dialog
              class="addP"
              title="退回简历"
              :visible.sync="backFormVisible"
              width="415px"
              :before-close="cancelBack"
            >
              <el-form :model="formL" :rules="rules" ref="formL" label-position="top">
                <el-form-item label="退回原因" :label-width="formLabelWidth" prop="reason">
                  <el-input
                    type="textarea"
                    :autosize="{minRows:2}"
                    v-model="formL.reason"
                    placeholder="请输入退回原因"
                  ></el-input>
                </el-form-item>
              </el-form>
              <div slot="footer" class="dialog-footer">
                <el-button class="sure" type="primary" round @click="backConfirm('formL')">确 定</el-button>
                <el-button class="cancel" round @click="cancelBack">取 消</el-button>
              </div>
            </el-dialog>
          </div>
        </el-col>
      </el-row>
    </div>
    <div v-if="type == 2">
      <job-Detail v-show="addShow" :detail-no="detailno"></job-Detail>
    </div>
    <div v-if="type == 3">
      <upload-Detail v-show="addShow" :detail-code="detailcode"></upload-Detail>
    </div>
  </div>
</template>
<script>
import axios from "axios";
import qs from "qs";
import JobDetail from "./jobdetail.vue";
import UploadDetail from "./uploaddetail.vue";
import moment from "moment";
import tagsView from "../../store/modules/tagsView";

export default {
  name: "resumepush",
  data() {
    return {
      theme: ``,
      inputValue: "",
      secondshow: false,
      form: {
        receiver: "",
        cpSendMail: "",
        secret: ""
      },
      receiveMails: [],
      resumeDetail: [],
      formL: {
        reason: ""
      },
      newcolor: false,
      newcolor1: false,
      jiaofu: true,
      isSecret: false,
      key: true,
      emailError: false,
      sendEmailKey: false,
      maildata: [],
      tableData: [],
      multipleSelection: [],
      mulLength: 0,
      msg: "",
      currentPage: 1,
      pagesize: 15,
      totalcount: 0,
      tableData1: [],
      currentPage1: 1,
      pagesize1: 5,
      totalcount1: 0,
      editdialogVisible: false,
      dialogFormVisible: false,
      backFormVisible: false,
      dialogVisible: false,
      requireNumDialogVisible: false,
      detailcode: "",
      detailno: "",
      type: null,
      iconClass: "el-icon-caret-right",
      secondtitle: "",
      addShow: false,
      file: null,
      formLabelWidth: "120px",
      rules: {
        reason: [{ required: true, message: "请输入退回原因", trigger: "blur" }]
      },
      mailform: [
        {
          JRNumber: "",
          Role: "",
          Name: "",
          NoticePeriod: "",
          Gender: "",
          YearofBirth: "",
          Experience: "",
          Note: "",
          Language: "",
          RateCode: "",
          Telephone: "",
          PersonalDataUsageDeclaration:
            "This is to confirm that:1. This candidate agreed that his/her personal data will be passed to HKEX user departments outside China for review or record purpose.2.The personal data handling is compliance to National Cyber security law."
        }
      ],
      isGang: false,
      header: []
    };
  },
  created() {
    this.success();
    this.getresult();
    if (tagsView.state.identity == 7) {
      this.jiaofu = false;
    }
  },
  methods: {
    //简历推送数量
    getresult() {
      axios
        .post(this.url + "/todaytask/task", {
          pageNum: this.currentPage1,
          pageSize: this.pagesize1
        })
        .then(res => {
          this.unlogin(res.data.code);
          if (res.data.code == 200) {
            this.tableData1 = res.data.data.list;
            this.totalcount1 = res.data.data.total;
          }
        });
    },
    reclose() {
      this.requireNumDialogVisible = false;
      document.documentElement.style.overflow = "auto";
    },
    filter(value) {
      return moment(value).format("YYYY-MM");
    },
    success() {
      axios
        .post(this.url + "/resumeUpload/getCommitResume", {
          condition: this.inputValue,
          pageNum: this.currentPage,
          pageSize: this.pagesize
        })
        .then(res => {
          this.unlogin(res.data.code);
          if (res.data.code == 200) {
            this.tableData = res.data.data.list;
            this.totalcount = res.data.data.total;
            if (this.currentPage > Math.ceil(this.totalcount / this.pagesize)) {
              this.currentPage = Math.ceil(this.totalcount / this.pagesize);
            }
          }
        });
    },
    getRowKey(row) {
      return row.id;
    },
    tableshow(row) {
      this.addShow = false;
      this.secondshow = false;
      this.$refs.multipleTable.setCurrentRow(row);
      this.type = null;
      this.success();
    },
    searchMsg() {
      this.currentPage = 1;
      axios
        .post(this.url + "/resumeUpload/getCommitResume", {
          condition: this.inputValue,
          pageNum: this.currentPage,
          pageSize: this.pagesize
        })
        .then(res => {
          this.unlogin(res.data.code);
          if (res.data.code == 200) {
            this.tableData = res.data.data.list;
            this.totalcount = res.data.data.total;
          }
        });
    },
    secretBlur() {
      var re = /^[A-Za-z\d]+(([-_.]*)+[A-Za-z\d]+)*@([A-Za-z\d]+[-.])+[A-Za-z\d]{2,4}$/;
      if (!re.test(this.form.secret)) {
        this.emailError = true;
      } else {
        this.emailError = false;
      }
    },
    // 推送按钮按下
    pushDown() {
      this.newcolor = true;
    },
    // 推送按钮弹起
    pushUp() {
      this.newcolor = false;
    },
    backDown() {
      this.newcolor1 = true;
    },
    backUp() {
      this.newcolor1 = false;
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    //推送按钮点击
    pushClick() {
      if (this.multipleSelection.length == 0) {
        this.editdialogVisible = true;
        document.documentElement.style.overflow = "hidden";
      } else {
        let arr = [];
        for (let i = 0, len = this.multipleSelection.length; i < len; i++) {
          arr.push(this.multipleSelection[i].requireNum);
        }
        axios
          .post(this.url + "/resumeUpload/isSameRequireNum", {
            requireNums: arr
          })
          .then(res => {
            if (res.data.code == 200 && res.data.message == "success") {
              this.mulLength = this.multipleSelection.length;
              let idArr = [];
              for (
                let i = 0, len = this.multipleSelection.length;
                i < len;
                i++
              ) {
                idArr.push(this.multipleSelection[i].id);
              }

              axios
                .post(this.url + "/mailTemplate/getMail", {
                  ids: idArr
                })
                .then(res => {
                  this.unlogin(res.data.code);
                  if (res.data.code == 200) {
                    this.header = res.data.data;
                  }
                });

              axios
                .post(this.url + "/resumeUpload/getPushResumeDetail", {
                  ids: idArr
                })
                .then(res => {
                  this.unlogin(res.data.code);
                  if (res.data.code == 200) {
                    this.receiveMails = res.data.data.receiveMails;
                    this.resumeDetail = res.data.data.resumeDetailS;
                    this.maildata = JSON.parse(
                      JSON.stringify(this.resumeDetail)
                    );
                    if (this.maildata[0].customerName == "港交所") {
                      this.mailform[0].Name = this.maildata[0].name;
                      this.mailform[0].Gender = this.maildata[0].sex;
                      this.mailform[0].YearofBirth = this.maildata[0].birthday
                        .match(/\d{4}/)
                        .join();
                      this.mailform[0].Experience = this.maildata[0].experience;
                      this.mailform[0].Telephone = this.maildata[0].phone;
                      this.mailform[0].Role = this.maildata[0].postName;
                      this.mailform[0].JRNumber = this.maildata[0].requireNum;
                      this.mailform[0].Note = this.maildata[0].initialEvaluation;
                      this.mailform[0].NoticePeriod = this.maildata[0].entryTime;
                      this.mailform[0].Language = this.maildata[0].remark;
                      this.mailform[0].RateCode = this.maildata[0].ratecode;
                      if (this.maildata.length > 1) {
                        for (
                          let i = 1, len = this.maildata.length;
                          i < len;
                          i++
                        ) {
                          this.mailform.push({
                            JRNumber: this.maildata[i].requireNum,
                            Role: this.maildata[i].postName,
                            Name: this.maildata[i].name,
                            NoticePeriod: this.maildata[i].entryTime,
                            Gender: this.maildata[i].sex,
                            YearofBirth: this.maildata[i].birthday.match(
                              /\d{4}/
                            ),
                            Experience: this.maildata[i].experience,
                            Note: this.maildata[i].initialEvaluation,
                            Language: this.maildata[i].remark,
                            RateCode: this.maildata[i].ratecode,
                            Telephone: this.maildata[i].phone,
                            PersonalDataUsageDeclaration:
                              "This is to confirm that:1. This candidate agreed that his/her personal data will be passed to HKEX user departments outside China for review or record purpose.2.The personal data handling is compliance to National Cyber security law."
                          });
                        }
                      }
                      this.isGang = true;
                    } else {
                      this.isGang = false;
                    }

                    if (this.maildata[0].customerName == "浦发信用卡") {
                      for (var i = 0; i < this.maildata.length; i++) {
                        this.maildata[i]["pushTime"] = moment(
                          new Date()
                        ).format("YYYY-MM-DD");
                      }
                    }

                    this.msg =
                      this.maildata[0].customerName + this.maildata[0].postName;
                    this.theme = `【候选人推送】-${this.resumeDetail[0].customerName}-${this.resumeDetail[0].postName}-${this.resumeDetail[0].name}（共${this.mulLength}个简历）`;
                    this.file = [];
                    for (
                      let i = 0, len = this.resumeDetail.length;
                      i < len;
                      i++
                    ) {
                      let obj = {};
                      if (this.maildata[0].customerName == "港交所") {
                        obj.fileUrl = this.resumeDetail[i].fileAddrEn;
                        obj.originalFilename = this.resumeDetail[i].fileNameEn;
                        this.file.push(obj);
                        let obj1 = {};
                        obj1.fileUrl =
                          "/" +
                          this.resumeDetail[i].group +
                          "/" +
                          this.resumeDetail[i].fileAddress;
                        obj1.originalFilename = this.resumeDetail[
                          i
                        ].originalFilename;
                        this.file.push(obj1);
                      } else {
                        obj.fileUrl =
                          "/" +
                          this.resumeDetail[i].group +
                          "/" +
                          this.resumeDetail[i].fileAddress;
                        obj.originalFilename = this.resumeDetail[
                          i
                        ].originalFilename;
                        this.file.push(obj);
                      }

                      this.resumeDetail[i].graduationTime = this.filter(
                        this.resumeDetail[i].graduationTime
                      );
                      this.resumeDetail[i].birthday = this.filter(
                        this.resumeDetail[i].birthday
                      );
                    }
                  }
                  this.editdialogVisible = false;
                  this.dialogFormVisible = true;
                  document.documentElement.style.overflow = "hidden";
                  this.success();
                });
            } else {
              this.requireNumDialogVisible = true;
              document.documentElement.style.overflow = "hidden";
            }
          });
      }
    },
    getcpMail(val) {
      let receiveMailId;
      for (let i = 0, len = this.receiveMails.length; i < len; i++) {
        if (this.receiveMails[i].receiveMail == val) {
          receiveMailId = this.receiveMails[i].id;
        }
      }
      axios
        .post(this.url + "/resumeUpload/getCpmails", {
          id: receiveMailId
        })
        .then(res => {
          this.unlogin(res.data.code);
          if (res.data.code == 200) {
            this.form.cpSendMail = res.data.data.join(",");
          }
        });
    },
    //退回按钮点击
    backClick() {
      if (this.multipleSelection.length == 0) {
        this.editdialogVisible = true;
        document.documentElement.style.overflow = "hidden";
      } else if (this.multipleSelection.length > 1) {
        this.dialogVisible = true;
        document.documentElement.style.overflow = "hidden";
      } else {
        this.editdialogVisible = false;
        this.backFormVisible = true;
        document.documentElement.style.overflow = "hidden";
      }
    },
    //退回原因确认
    backConfirm(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          axios
            .post(
              this.url + "/resumeUpload/rejectResume",
              qs.stringify({
                id: this.multipleSelection[0].id,
                rejectReason: this.formL.reason
              })
            )
            .then(res => {
              this.unlogin(res.data.code);
              if (res.data.code == 200) {
                this.backFormVisible = false;
                document.documentElement.style.overflow = "auto";
                this.$refs.formL.resetFields();
                this.currentPage = 1;
                this.success();
                this.multipleSelection = [];
                this.$refs.multipleTable.clearSelection();
              }
            });
        }
      });
    },
    //取消退回
    cancelBack() {
      this.backFormVisible = false;
      document.documentElement.style.overflow = "auto";
    },
    handleSizeChange(val) {
      this.pagesize = val;
      this.success();
    },
    pagehandleCurrentChange(val) {
      this.currentPage = val;
      this.success();
    },
    handleSizeChange1(val) {
      this.pagesize1 = val;
      this.getresult();
    },
    pagehandleCurrentChange1(val) {
      this.currentPage1 = val;
      this.getresult();
    },
    viewdetail(val) {
      this.detailcode = val;
      this.addShow = !this.addShow;
      this.secondtitle = "查看上传内容";
      this.secondshow = !this.secondshow;
      this.type = 3;
    },
    viewjobdemand(val) {
      this.detailno = val.requireNum;
      this.addShow = !this.addShow;
      this.secondtitle = "职位需求";
      this.secondshow = true;
      this.type = 2;
    },
    // 请选择简历警告 隐藏方法
    handleOpen() {
      this.editdialogVisible = false;
      document.documentElement.style.overflow = "auto";
    },
    handleClose() {
      this.editdialogVisible = false;
      document.documentElement.style.overflow = "auto";
    },
    sendClick() {
      let id = [];
      for (let i = 0, len = this.multipleSelection.length; i < len; i++) {
        id.push(this.multipleSelection[i].id);
      }
      if (!this.isGang) {
        axios
          .post(this.url + "/resumeUpload/pushResume", {
            receiveMail: this.form.receiver,
            cpSendMails: this.form.cpSendMail,
            secretMail: this.form.secret,
            subject: this.theme,
            files: this.file,
            resumeDetails: this.maildata,
            content: id
          })
          .then(res => {
            this.unlogin(res.data.code);
            if (res.data.code == 200) {
              this.dialogFormVisible = false;
              document.documentElement.style.overflow = "auto";
              this.multipleSelection = [];
              this.key = true;
              this.iconClass = "el-icon-caret-right";
              this.isSecret = false;
              this.currentPage = 1;
              this.currentPage1 = 1;
              this.success();
              this.getresult();
              this.$refs.multipleTable.clearSelection();
            }
          });
      } else {
        axios
          .post(this.url + "/resumeUpload/pushGJSResume", {
            receiveMail: this.form.receiver,
            cpSendMails: this.form.cpSendMail,
            secretMail: this.form.secret,
            subject: this.theme,
            files: this.file,
            content: id,
            gjsResumes: this.mailform
          })
          .then(res => {
            this.unlogin(res.data.code);
            if (res.data.code == 200) {
              this.dialogFormVisible = false;
              document.documentElement.style.overflow = "auto";
              this.multipleSelection = [];
              this.key = true;
              this.iconClass = "el-icon-caret-right";
              this.isSecret = false;
              this.currentPage = 1;
              this.currentPage1 = 1;
              this.success();
              this.getresult();
              this.$refs.multipleTable.clearSelection();
            }
          });
      }
    },
    cancelSend() {
      this.dialogFormVisible = false;
      document.documentElement.style.overflow = "auto";
      this.key = true;
      this.iconClass = "el-icon-caret-right";
      this.isSecret = false;
    },
    // 每次退回一份简历警告 隐藏
    open() {
      this.dialogVisible = false;
      document.documentElement.style.overflow = "auto";
    },
    close() {
      this.dialogVisible = false;
      document.documentElement.style.overflow = "auto";
    },
    secretAppear() {
      if (this.key) {
        this.isSecret = true;
        this.iconClass = "el-icon-caret-bottom";
        this.key = false;
      } else {
        this.isSecret = false;
        this.iconClass = "el-icon-caret-right";
        this.key = true;
      }
    }
  },
  watch: {
    inputValue: function(val) {
      if (val == "") {
        this.currentPage = 1;
        this.success();
      }
    },
    dialogFormVisible: function(val) {
      if (val) {
        this.form.receiver = "";
        this.form.cpSendMail = "";
      }
    },
    "form.receiver": function(val) {
      if (val == "") {
        this.sendEmailKey = false;
      } else {
        this.sendEmailKey = true;
      }
    }
  },
  components: {
    JobDetail,
    UploadDetail
  }
};
</script>
<style scoped>
.title {
  background-color: #fff;
  height: 40px;
  line-height: 40px;
  font-size: 14px;
  padding-left: 20px;
  margin-top: 6px;
  margin-bottom: 6px;
}

.textactive {
  color: #1099ff;
}

.posttable {
  min-height: 700px;
  background-color: #fff;
}

.push {
  width: 65px;
  height: 28px;
  opacity: 0.86;
  color: #fff;
  background: linear-gradient(to bottom, #ffbc1c 0%, #f69710 100%);
  padding: 7px 15px !important;
}

.push:hover {
  color: #fff !important;
}

.back {
  width: 65px;
  height: 28px;
  opacity: 0.86;
  color: #fff;
  background: linear-gradient(to bottom, #8490e2 0%, #6f7acc 100%);
  padding: 7px 15px !important;
}

.back:hover {
  color: #fff !important;
}

.active {
  background: linear-gradient(to bottom, #ff9600 0%, #d68300 100%);
}

.active1 {
  background: linear-gradient(to bottom, #6676e0 0%, #5260c7 100%);
}

.resutable {
  background-color: #fff;
}

.pager {
  margin-top: 20px;
}

.pager {
  width: 100%;
  overflow: hidden;
  position: relative;
  margin-top: 10px;
  margin-bottom: 10px;
}

.el-pagination {
  margin-left: 50%;
  transform: translateX(-50%);
}

.resumeLink {
  cursor: pointer;
  color: #1198ff;
  text-decoration: none;
}

.line {
  height: 1px;
  background-color: #c8c8c8;
  margin-top: 3px;
  margin-bottom: 20px;
}

.darkline {
  height: 1px;
  background-color: #4288c3;
  margin-top: 10px;
  margin-bottom: 20px;
}

.lightLine {
  height: 1px;
  background-color: #cccccc;
  margin-top: 10px;
  margin-bottom: 10px;
}

.tablelist {
  width: 100%;
  /*overflow-x:scroll;*/
}
</style>
